
const token=localStorage.getItem("token")

async function requestTeachingClass(){
    const url=`${config.server}`+"/api/admin/select/teaching/class"
    const data={
        "token":token
    }
    const response=await fetch(url,{
        method:"POST",
        headers: { 'Content-Type': 'application/json' },
        body:JSON.stringify(data)
    })
    const getdata=await response.json()
    if(response.ok){
        console.log(getdata)

        return getdata
    }else{
        console.log("获取数据失败",getdata)
    }
}

const myTeachClassTable=document.getElementById("myTeachClassTable")
const tbody = myTeachClassTable.querySelector('tbody');
async function displayMyTeachClass(){
    const data= await requestTeachingClass()

    data.forEach(function(row){
        const newRow=document.createElement("tr")

        const td1=document.createElement("td")
        td1.innerText=row.ClassName
        newRow.appendChild(td1)

        const td2=document.createElement("td")
        td2.textContent=row.AlreadActive ? "是": "否"
        newRow.appendChild(td2)

        const td3=document.createElement("td")
        td3.textContent=row.DayOfWeek
        newRow.appendChild(td3)

        const td4=document.createElement("td")
        td4.textContent=row.index
        newRow.appendChild(td4)

        const td5=document.createElement("td")
        td5.textContent=row.Auto ? "是": "否"
        newRow.appendChild(td5)

        const td6=document.createElement("td")
        td6.innerText="查看课程"
        td6.addEventListener("click",()=>{
            location.href=`../../pages/course/course.html?course_id=${row.CourseId}`
        })
        td6.style.border="3px solid blue"
        newRow.appendChild(td6)

        tbody.appendChild(newRow)
    })

}
displayMyTeachClass()